'''
Created on Nov 17, 2010

@author: oabalbin
'''
import ConfigParser
from collections import deque, defaultdict

def config_run(configfile_name):
    '''
    It returns a dictionary with all the programs and
    parameters which are to be run/ 
    '''
    config = ConfigParser.ConfigParser()
    config.read(configfile_name)
    sections = config.sections()
    configlist=defaultdict(defaultdict)

    for thsection in sections:
        for item in config.items(thsection):
            configlist[thsection][item[0]]= item[1]
    
    return configlist


def config_experiment(configfile_name):
    '''
    It returns a dictionary with all parameters needed to run the script that it is calling it
    '''
    print configfile_name
    config = ConfigParser.ConfigParser()
    config.read(configfile_name)
    sections = config.sections()
    
    sampledict=defaultdict()
    configlist=defaultdict()
    for thsection in sections:
        # get items:
        thit = config.items(thsection)
        if thsection=='SampleDir':
            for sp in thit:
                if sp[0]!='dir':
                    sampledict[sp[0]]=sp[1]
            configlist[thsection]=sampledict
        else:
            configlist[thsection]=thit
    
    return configlist